
export interface TextPart {
    text: string;
}

export interface FilePart {
    fileName: string;
    fileUri: string;
}

export interface FormValue {
    key: string;
    value: string;
}

export interface FormPart {
    values: FormValue[];
    submit: boolean;  //触发表单提交
}

export interface Part {
    textPart?: TextPart;
    filePart?: FilePart;
    formPart?: FormPart;
}

export interface Message {
    messageId: string;
    timeStamp: number; //1970年以来的毫秒数
    role: "user" | "agent";
    parts: Part[];
    kind: "message";
}

export interface Artifact {
    artifactId: string;
    name: string;
    description: string;
    timeStamp: number; //1970年以来的毫秒数
    parts: Part[];
}

export interface FormField {
    name: string;
    description: string;
    key: string;
    value: string;
    valueType: "date" | "datetime" | "email" | "fileurl" | "number" | "text";
    optional: boolean;
}

export interface FormDefine {
    formDefineId: string;
    formType: string;
    name: string;
    description: string;
    timeStamp: number; //1970年以来的毫秒数
    fields: FormField[];
}

/*
 * 只有在state为input-required，才显示输入框
 * createed 任务处于新建状态，未进入处理流程
 * working 正在执行任务
 * input-required 需要用户输入
 * completed 任务完成(终止状态)
 * canceled 任务取消执行(终止状态)
 * failed 任务执行失败(终止状态)
 * rejected 拒绝执行任务(终止状态)
 */

export interface TaskStatus {
    state: "createed" | "working" | "input-required" | "completed" | "canceled" | "failed" | "rejected";
    message?: Message;
    timeStamp: number; //1970年以来的毫秒数
}

export interface TaskStatusUpdateEvent {
    taskId: string;
    status: TaskStatus;
    final: boolean;
    kind: "status-update";
}

export interface TaskArtifactUpdateEvent {
    taskId: string;
    artifact: Artifact;
    kind: "artifact-update";
}

export interface TaskFormDefineUpdateEvent {
    taskId: string;
    formDefine: FormDefine;
    kind: "formdefine-update";
}

export interface Task {
    taskId: string;
    ownerId: string; //任务所属用户
    status: TaskStatus;
    skillId: string; //技能ID
    messages: Message[];
    artifacts: Artifact[];
    formDefines: FormDefine[];
}

export interface Skill {
    skillId: string;
    name: string;
    description: string;
    filterUserRole: boolean;
    userRoles: string[];
    examples: string[]; //提示词例子
    default: boolean; //是否是默认技能
}

export interface AuthProvider {
    getAuthHeader(): Record<string, string>;
}

export interface TaskEventWatch {
    onEvnet(ev: Message | TaskStatusUpdateEvent | TaskArtifactUpdateEvent | TaskFormDefineUpdateEvent): void;
    onReady(): void;
}